package com.own.business.system.dictionary.adapter.manage.controller;

import com.own.aop.permission.PermissionModule;
import com.own.aop.permission.PermissionOperation;
import com.own.business.system.dictionary.adapter.method.SystemDictionaryManageParentMethod;
import com.own.business.system.dictionary.adapter.model.DictionaryParentModel;
import com.own.business.system.dictionary.adapter.model.DictionaryParentQuery;
import com.own.component.common.base.controller.BaseController;
import com.own.component.common.model.PageModel;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import com.own.component.log.operation.aop.LogOperationAop;
import com.own.component.store.core.confirm.aop.ConfirmAop;
import com.own.constant.ConstantApiPrefix;
import com.own.constant.ConstantBeanSuffix;
import com.own.constant.ConstantPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * SystemDictionaryAdapterManageParentController
 *
 * @author chenxueli
 * @date 2023-06-21 09:53:26
 */
@Tag(name = "数据字典类型" + ConstantBeanSuffix.CONTROLLER)
@PermissionModule("system-dictionary-parent")
@RestController
@RequestMapping(ConstantApiPrefix.BASE_API_V1_PREFIX + ConstantApiPrefix.MANAGE_CLIENT + "system/dictionary/adapter/parent")
public class SystemDictionaryAdapterManageParentController extends BaseController {

    @Resource
    private SystemDictionaryManageParentMethod systemDictionaryManageParentMethod;

    @LogOperationAop
    @PermissionOperation(ConstantPermission.SEARCH)
    @Operation(summary = "查询全部信息")
    @PostMapping("/all")
    public ResultModel<List<DictionaryParentModel>> all(
            @RequestBody DictionaryParentQuery query
    ) {
        var list = systemDictionaryManageParentMethod.all(query);
        return R.success(list);
    }

    @LogOperationAop
    @PermissionOperation(ConstantPermission.SEARCH)
    @Operation(summary = "分页查询信息")
    @PostMapping("/page")
    public ResultModel<PageModel<DictionaryParentModel>> page(
            @RequestBody DictionaryParentQuery query
    ) {
        var pageModel = systemDictionaryManageParentMethod.page(query);
        return R.success(pageModel);
    }

    @LogOperationAop
    @PermissionOperation(ConstantPermission.ADD)
    @Operation(summary = "添加信息")
    @PostMapping("/")
    public ResultModel<Boolean> add(
            @Validated @RequestBody DictionaryParentModel model
    ) {
        systemDictionaryManageParentMethod.add(model);
        return R.success();
    }

    @LogOperationAop
    @PermissionOperation(ConstantPermission.UPDATE)
    @Operation(summary = "修改信息")
    @PutMapping("/{dictionaryId}")
    public ResultModel<Boolean> update(
            @Parameter(description = "主键id", required = true) @PathVariable Long dictionaryId,
            @Validated @RequestBody DictionaryParentModel model
    ) {
        systemDictionaryManageParentMethod.update(dictionaryId, model);
        return R.success();
    }

    @LogOperationAop
    @PermissionOperation(ConstantPermission.DELETE)
    @ConfirmAop(message = "确认删除该数据字典类型？（注意：删除之后无法找回数据，且会删除所有的该类型的项目数据）")
    @Operation(summary = "删除信息")
    @DeleteMapping("/{dictionaryId}")
    public ResultModel<Boolean> delete(
            @Parameter(description = "主键id", required = true) @PathVariable Long dictionaryId
    ) {
        systemDictionaryManageParentMethod.delete(dictionaryId);
        return R.success();
    }

    @LogOperationAop
    @PermissionOperation(ConstantPermission.VIEW)
    @Operation(summary = "根据id获取信息")
    @GetMapping("/{dictionaryId}")
    public ResultModel<DictionaryParentModel> getById(
            @Parameter(description = "主键id", required = true) @PathVariable Long dictionaryId
    ) {
        var vo = systemDictionaryManageParentMethod.getById(dictionaryId);
        return R.success(vo);
    }

}
